#include "recovery/fs/file/FileRandomReader.h"

#include "recovery/fs/file/File.h"
namespace recovery {
namespace fs {
namespace file {

ErrnoStatus FileRandomReader::openExist(const std::string & path, std::unique_ptr<FileRandomReader> & reader){
    reader.reset(new FileRandomReader(path));
    return reader->file().openForRandomRead(reader->writableFd());
}

FileRandomReader::FileRandomReader(const std::string & path)
: AbstractFileOperation(path, true)
{
}

ErrnoStatus FileRandomReader::read(char * buf, const size_t len, size_t & readBytes){
    return file().read(fd(), reinterpret_cast<uint8_t*>(buf), len, readBytes);
}
ErrnoStatus FileRandomReader::closeOnce(){
    return file().close(fd());
}

} //end of namespace file
} //end of namespace fs
} //end of namespace recovery

